<%-- 
    Document   : settings
    Created on : Apr 13, 2012, 9:53:35 AM
    Author     : Mr. Hung
--%>

 <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.util.Calendar"%>
<%@page import="java.util.Date"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="business.Account"%>
<%@page import="java.util.HashMap"%>
<%@page import="java.util.Map"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link href="images/favicon.ico" rel="shortcut icon" type="image/x-icon" media="all" />
        <link href="style.css" rel="stylesheet" type="text/css" />
        <title>Settings</title>
    </head>
    <body>
        <c:import url="/header.jsp" />
        <c:import url="/leftbar.jsp" />
        <div id="wrapper">
            
            
            <div id="content_wrapper"><span class="top"></span><span class="bottom"></span>
                <div id="content">
                    <c:if test="${message != null}">
                        <h3>
                            <font color="red">${message}</font>
                        </h3>
                    </c:if>
                    <form action="Settings" method="post">
                        <div id="avt">
                            <table>
                                <td width="135"> <img src="${account.avatar}" height="100" width="100"></td>          
                                <td valign="bottom"><h4>Avatar URL: </h4><input size="70" type="text" name="avatar" value="${account.avatar}"></td>
                            </table>
                        </div>
                        <div class="settings_box">   
                            <h3>Basic information:</h3>
                            <table>
                                <tr>
                                    <td align="right"><label>Username:</label></td>
                                    <td width="10"></td>
                                    <td><input type="text" size="26" readonly="readonly" value="${account.username}"></td>
                                </tr>
                                <tr>
                                    <td align="right"><label>Email Address:</label></td>
                                    <td width="10"></td>
                                    <td><input type="text" size="26" readonly="readonly" value="${account.emailAddress}"></td>
                                </tr>
                                <tr>
                                    <%-- display birthday --%>
                                    <td align="right"><label>Birthday:</label></td>
                                    <td width="10"></td>
                                    <%
                                        Account acc = (Account) request.getAttribute("account");
                                        Date birthday = (Date) acc.getBirthday();
                                        log("birthday:" + birthday);

                                        SimpleDateFormat formater = new SimpleDateFormat("dd");
                                        int day = Integer.parseInt(formater.format(birthday));

                                        formater = new SimpleDateFormat("MM");
                                        int month = Integer.parseInt(formater.format(birthday));

                                        formater = new SimpleDateFormat("yyyy");
                                        int year = Integer.parseInt(formater.format(birthday));

                                        request.setAttribute("_day", day);
                                        request.setAttribute("_month", month);
                                        request.setAttribute("_year", year);
                                        log("_day:" + day + " _month:" + month + " _year:" + year);
                                    %>
                                    <td>
                                        <select name="day">
                                            <c:forEach begin="1" end="31" varStatus="status">
                                                <c:choose>
                                                    <c:when test="${status.index == _day}">
                                                        <option selected>${status.index}</option>
                                                    </c:when>
                                                    <c:otherwise>
                                                        <option >${status.index}</option>
                                                    </c:otherwise>
                                                </c:choose>
                                            </c:forEach>
                                        </select>
                                        
                                        <select name="month" >
                                            <c:forEach begin="1" end="12" varStatus="status">
                                                <c:choose>
                                                    <c:when test="${status.index == _month}">
                                                        <option selected>${status.index}</option>
                                                    </c:when>
                                                    <c:otherwise>
                                                        <option >${status.index}</option>
                                                    </c:otherwise>
                                                </c:choose>
                                            </c:forEach>
                                        </select>
                                        
                                        <select name="year">
                                            <c:forEach begin="1970" end="2006" varStatus="status">
                                                <c:choose>
                                                    <c:when test="${status.index == _year}">
                                                        <option selected>${status.index}</option>
                                                    </c:when>
                                                    <c:otherwise>
                                                        <option >${status.index}</option>
                                                    </c:otherwise>
                                                </c:choose>
                                            </c:forEach>
                                        </select>
                                    </td>   
                                    
                                </tr>
                                <tr>
                                    <%-- display gender --%>
                                    <td align="right"><label>Gender:</label></td>
                                    <td width="10"></td>
                                    <td>
                                        
                                        <c:choose>
                                            <c:when test="${account.gender == 'female'}">
                                                <input type="radio" name="gender" value="female"checked>Female
                                                <input type="radio" name="gender" value="male">Male
                                            </c:when>
                                            <c:otherwise>
                                                <input type="radio" name="gender" value="female">Female
                                                <input type="radio" name="gender" value="male" checked>Male
                                            </c:otherwise>
                                        </c:choose>
                                        
                                    </td>
                                </tr>
                                <tr>
                                    <%-- Display friend gender --%>
                                    <td align="right"><label>Friend Gender:</label></td>
                                    <td width="10"></td>
                                    <td>
                                        <c:choose>
                                            <c:when test="${account.interestGender == 'female'}">
                                                <input type="radio" name="interestGender" value="female"checked>Female
                                                <input type="radio" name="interestGender" value="male">Male
                                                <input type="radio" name="interestGender" value="both">Both
                                            </c:when>
                                            <c:when test="${account.interestGender == 'male'}">
                                                <input type="radio" name="interestGender" value="female">Female
                                                <input type="radio" name="interestGender" value="male" checked>Male
                                                <input type="radio" name="interestGender" value="both">Both
                                            </c:when>
                                            <c:otherwise>
                                                <input type="radio" name="interestGender" value="female">Female
                                                <input type="radio" name="interestGender" value="male">Male
                                                <input type="radio" name="interestGender" value="both" checked>Both
                                            </c:otherwise>
                                        </c:choose> 
                                    </td>
                                </tr>
                            </table>
                        </div>
                        
                        <div class="settings_box">       
                            <h3>Hobbies and Dislikes:</h3>
                            <%
                                HashMap<String, String> map = new HashMap<String, String>();
                            %>
                            <c:forEach var="hobby" items="${account.hobbies}">
                                <c:choose>
                                    <c:when test="${hobby == 'music'}">
                                        <% map.put("music", "like");
                                            System.out.println("music is putted");
                                        %>
                                    </c:when>
                                    <c:when test="${hobby == 'movie'}">
                                        <% map.put("movie", "like");%>
                                    </c:when>
                                    <c:when test="${hobby == 'book'}">
                                        <% map.put("book", "like");%>
                                    </c:when>
                                    <c:when test="${hobby == 'sport'}">
                                        <% map.put("sport", "sport");%>
                                    </c:when>
                                    <c:when test="${hobby == 'game'}">
                                        <% map.put("game", "like");%>
                                    </c:when>
                                </c:choose>
                            </c:forEach>
                            
                            <c:forEach var="dislike" items="${account.dislikes}">
                                <c:choose>
                                    <c:when test="${dislike == 'music'}">
                                        <% map.put("music", "dislike");%>
                                    </c:when>
                                    <c:when test="${dislike == 'movie'}">
                                        <% map.put("movie", "dislike");%>
                                    </c:when>
                                    <c:when test="${dislike == 'book'}">
                                        <% map.put("book", "dislike");%>
                                    </c:when>
                                    <c:when test="${dislike == 'sport'}">
                                        <% map.put("sport", "dislike");%>
                                    </c:when>
                                    <c:when test="${dislike == 'game'}">
                                        <% map.put("game", "dislike");%>
                                    </c:when>
                                </c:choose>
                            </c:forEach>
                            
                            <%
                                request.setAttribute("_map", map);
                            %>
                            
                            <table>
                                <tr>
                                    <td width="58"></td>
                                    <td align="right"><label>Music:</label></td>
                                    <td width="15"></td>
                                    <td>
                                        <c:choose>
                                            <c:when test="${_map.music =='like'}">
                                                <input type="radio" name="music" value ="like" checked>Like
                                                <input type="radio" name="music" value="dislike">Dislike
                                                <input type="radio" name="music" value="no idea">No idea
                                            </c:when>
                                            <c:when test="${_map.music == 'dislike'}">
                                                <input type="radio" name="music" value ="like">Like
                                                <input type="radio" name="music" value="dislike" checked>Dislike
                                                <input type="radio" name="music" value="no idea">No idea
                                            </c:when>
                                            <c:otherwise>
                                                <input type="radio" name="music" value="like">Like
                                                <input type="radio" name="music" value="dislike">Dislike
                                                <input type="radio" name="music" value="no idea" checked>No idea
                                            </c:otherwise>
                                        </c:choose>
                                    </td>
                                    
                                <tr>
                                    <td width="58"></td>
                                    <td align="right"><label>Movie:</label></td>
                                    <td width="15"></td>
                                    <td>
                                        <c:choose>
                                            <c:when test="${_map.movie == 'like'}">
                                                <input type="radio" name="movie" value="like" checked>Like
                                                <input type="radio" name="movie" value="dislike">Dislike
                                                <input type="radio" name="movie" value="no idea">No idea
                                            </c:when>
                                            <c:when test="${_map.movie == 'dislike'}">
                                                <input type="radio" name="movie" value="like">Like
                                                <input type="radio" name="movie" value="dislike" checked>Dislike
                                                <input type="radio" name="movie" value="no idea">No idea
                                            </c:when>
                                            <c:otherwise>
                                                <input type="radio" name="movie" value="like">Like
                                                <input type="radio" name="movie" value="dislike">Dislike
                                                <input type="radio" name="movie" value="no idea" checked>No idea
                                            </c:otherwise>
                                        </c:choose>
                                    </td>
                                </tr>
                                
                                <tr>
                                    <td width="58"></td>
                                    <td align="right"><label>Book:</label></td>
                                    <td width="15"></td>
                                    <td>
                                        <c:choose>
                                            <c:when test="${_map.book == 'like'}">
                                                <input type="radio" name="book" value="like" checked>Like
                                                <input type="radio" name="book" value="dislike">Dislike
                                                <input type="radio" name="book" value="no idea">No idea
                                            </c:when>
                                            <c:when test="${_map.movie == 'dislike'}">
                                                <input type="radio" name="book" value="like">Like
                                                <input type="radio" name="book" value="dislike" checked>Dislike
                                                <input type="radio" name="book" value="no idea">No idea
                                            </c:when>
                                            <c:otherwise>
                                                <input type="radio" name="book" value="like">Like
                                                <input type="radio" name="book" value="dislike">Dislike
                                                <input type="radio" name="book" value="no idea" checked>No idea
                                            </c:otherwise>
                                        </c:choose>
                                    </td>
                                </tr>
                                
                                <tr>
                                    <td width="58"></td>
                                    <td align="right"><label>Sport:</label></td>
                                    <td width="15"></td>
                                    <td>
                                        <c:choose>
                                            <c:when test="${_map.sport == 'like'}">
                                                <input type="radio" name="sport" value="like" checked>Like
                                                <input type="radio" name="sport" value="dislike">Dislike
                                                <input type="radio" name="sport" value="no idea">No idea
                                            </c:when>
                                            <c:when test="${_map.sport == 'dislike'}">
                                                <input type="radio" name="sport" value="like">Like
                                                <input type="radio" name="sport" value="dislike" checked>Dislike
                                                <input type="radio" name="sport" value="no idea">No idea
                                            </c:when>
                                            <c:otherwise>
                                                <input type="radio" name="sport" value="like">Like
                                                <input type="radio" name="sport" value="dislike">Dislike
                                                <input type="radio" name="sport" value="no idea" checked>No idea
                                            </c:otherwise>
                                        </c:choose>
                                    </td>
                                </tr>
                                
                                <tr>
                                    <td width="58"></td>
                                    <td align="right"><label>Games:</label></td>
                                    <td width="15"></td>
                                    <td>
                                        <c:choose>
                                            <c:when test="${_map.game == 'like'}">
                                                <input type="radio" name="game" value="like" checked>Like
                                                <input type="radio" name="game" value="dislike">Dislike
                                                <input type="radio" name="game" value="no idea">No idea
                                            </c:when>
                                            <c:when test="${_map.game == 'dislike'}">
                                                <input type="radio" name="game" value="like">Like
                                                <input type="radio" name="game" value="dislike" checked>Dislike
                                                <input type="radio" name="game" value="no idea">No idea
                                            </c:when>
                                            <c:otherwise>
                                                <input type="radio" name="game" value="like">Like
                                                <input type="radio" name="game" value="dislike">Dislike
                                                <input type="radio" name="game" value="no idea" checked>No idea
                                            </c:otherwise>
                                        </c:choose>
                                    </td>
                                </tr>
                            </table>
                        </div>
                        
                        <div class="settings_box">
                            <h3>Study and Job:</h3>
                            <table>
                                <tr>
                                    <td width="60"></td>
                                    <td align="right" valign="top"><label>School:</label></td>
                                    <td width="20"></td>
                                    <td><textarea rows="3" cols="25" name="school" value="${account.career.school}"></textarea></td>
                                </tr>
                                <tr height="4">
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                </tr>
                                <tr>
                                    <td width="60"></td>
                                    <td align="right" valign="top"><label>Job:</label></td>
                                    <td width="20"></td>
                                    <td><input type="text" size="26" name="job" value="${account.career.job}"></td
                                </tr>
                            </table>
                        </div>
                        
                        <div class="settings_box">
                            <h3>Residence:</h3> 
                            <table>
                                <tr>
                                    <td width="30"></td>
                                    <td align="right" valign="top"><label>Address:</label></td>
                                    <td width="20"></td>
                                    <td><textarea rows="3" cols="25" name="address" value="${account.location.address}"></textarea></td>
                                </tr>
                                <tr height="4">
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                </tr>
                                <tr>
                                    <td width="30"></td>
                                    <td align="right" valign="top"><label>Home town:</label></td>
                                    <td width="20"></td>
                                    <td>
                                        <select name="hometown">
                                            <c:forEach var="town" items="${hometownList}" >
                                                <c:choose>
                                                    <c:when test="${town == account.location.hometown}">
                                                        <option selected>${town}</option>
                                                    </c:when>
                                                    <c:otherwise>
                                                        <option>${town}</option>
                                                    </c:otherwise>
                                                </c:choose>
                                            </c:forEach>
                                                    <c:choose>
                                                        <c:when test="${account.location.hometown == null || account.location.hometown == ''}">
                                                            <option selected></option>
                                                        </c:when>
                                                        <c:otherwise>
                                                            <option></option>
                                                        </c:otherwise>
                                                    </c:choose>
                                        </select>
                                    </td>
                                </tr>
                                <tr height="4">
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                </tr>
                                <tr>
                                    <td width="30"></td>
                                    <td align="right" valign="top"><label>Country:</label></td>
                                    <td width="20"></td>
                                    <td><input type="text" size="26" name="country" value="Vietnam" disabled="true"></td>
                                </tr>
                            </table> 
                        </div>
                        <input id="save" type="submit" value="Save changes">
                    </form>
                </div> <!-- end of content -->
                
                <div id="sidebar">
                    <div class ="profile_box">
                        <a href="personal.jsp">
                            <h2 align="center">${account.username}</h2>
                        </a>
                        <a id="avatar" href="personal.jsp" >
                            <img src="images/shin.jpg" height="250" width="250"> 
                        </a>
                    </div>
                    <div class="news_box">
                        <a href="friends.jsp"> <h2 align="center">Friend list (${sessionScope.account.numOfFriends})</h2></a>
                        <table>
                            <tr>
                                <td width="80">
                                    <a href="">
                                        <img src="images/shin.jpg" height="70" width="70">
                                    </a>
                                </td>
                                <td valign="top">
                                    <a href="">Friend Name</a>
                                </td>
                            </tr>
                            <tr>
                                <td width="80">
                                    <a href="">
                                        <img src="images/shin.jpg" height="70" width="70">
                                    </a>
                                </td>
                                <td valign="top">
                                    <a href="">Friend Name</a>
                                </td>
                            </tr>
                            <tr>
                                <td width="80">
                                    <a href="">
                                        <img src="images/shin.jpg" height="70" width="70">
                                    </a>
                                </td>
                                <td valign="top">
                                    <a href="">Friend Name</a>
                                </td>
                            </tr>
                            <tr>
                                <td width="80">
                                    <a href="">
                                        <img src="images/shin.jpg" height="70" width="70">
                                    </a>
                                </td>
                                <td valign="top">
                                    <a href="">Friend Name</a>
                                </td>
                            </tr>
                            <tr>
                                <td width="80">
                                    <a href="">
                                        <img src="images/shin.jpg" height="70" width="70">
                                    </a>
                                </td>
                                <td valign="top">
                                    <a href="">Friend Name</a>
                                </td>
                            </tr>
                        </table>
                    </div>
                    <div class="cleaner"></div>  
                </div>
                
                <div class="cleaner"></div>
            </div>
            
            <div class="cleaner"></div>
            
        </div> <!-- end of content_wrapper -->
        
        <c:import url="/footer.jsp" />
    </body>
</html>